﻿using Caliburn.Micro;
using Wulong.Phone.Qiushi.i18n;
using Wulong.Phone.Qiushi.ViewModels.Messages;

namespace Wulong.Phone.Qiushi.ViewModels
{
    public enum QiushiSectionEnum
    {
        Latest,
        EightHours,
        TwentyFourHours,
        Weekly,
        Monthly,
        PicStory
    }
    public class QiushiSectionsViewModel :Screen
    {

        private INavigationService _navigationService;
        private readonly IEventAggregator _events;
        public QiushiSectionsViewModel(INavigationService navigationService, IEventAggregator events)
        {
            _navigationService = navigationService;
            _events = events;
            _selectedIndex = -1;
        }

        private int _selectedIndex;

        public int SelectedIndex
        {
            get { return _selectedIndex; }
            set
            {
                if (_selectedIndex == value)
                    return;
                _selectedIndex = value;
                NotifyOfPropertyChange(() => SelectedIndex);
            }
        }

        public void NavigateToQiushiListView(int selectedIndex)
        {
            switch ((QiushiSectionEnum)selectedIndex)
            {
                case QiushiSectionEnum.Latest:
                    _navigationService.UriFor<QiushiListViewModel>()
                        .WithParam(x=>x.DisplayName, AppResources.VM_QiushiSection_Latest)
                        .WithParam(x => x.Section, "late")
                        .Navigate();
                    _events.Publish(new RefreshListMessage());
                    break;
                case QiushiSectionEnum.EightHours:
                    _navigationService.UriFor<QiushiListViewModel>()
                        .WithParam(x => x.DisplayName, AppResources.VM_QiushiSection_8hrs)
                        .WithParam(x => x.Section, "8hr")
                        .Navigate();
                    break;
                case QiushiSectionEnum.TwentyFourHours:
                    _navigationService.UriFor<QiushiListViewModel>()
                        .WithParam(x => x.DisplayName, AppResources.VM_QiushiSection_24hrs)
                        .WithParam(x => x.Section, "hot")
                        .Navigate();
                    break;
                case QiushiSectionEnum.Weekly:
                    _navigationService.UriFor<QiushiListViewModel>()
                        .WithParam(x => x.DisplayName, AppResources.VM_QiushiSection_WeeklyHottest)
                        .WithParam(x => x.Section, "week")
                        .Navigate();
                    break;
                case QiushiSectionEnum.Monthly:
                    _navigationService.UriFor<QiushiListViewModel>()
                        .WithParam(x => x.DisplayName, AppResources.VM_QiushiSection_MonthlyHottest)
                        .WithParam(x => x.Section, "month")
                        .Navigate();
                    break;
                case QiushiSectionEnum.PicStory:
                    _navigationService.UriFor<QiushiListViewModel>()
                        .WithParam(x => x.DisplayName, AppResources.VM_QiushiSection_Picstory)
                        .WithParam(x => x.Section, "pic")
                        .Navigate();
                    break;
                default:
                    break;
            }
            
        }

        protected override void OnDeactivate(bool close)
        {
            SelectedIndex = -1;
            base.OnDeactivate(close);
        }
    }
}
